package com.slkj.shilixiaoyuanapp.ui.main.community;

import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.example.api.InjectParam;
import com.slkj.shilixiaoyuanapp.R;
import com.slkj.shilixiaoyuanapp.base.ActivityInfo;
import com.slkj.shilixiaoyuanapp.base.BaseActivity;
import com.slkj.shilixiaoyuanapp.entity.CommunityEntity;
import com.slkj.shilixiaoyuanapp.entity.CommunityListEntity;
import com.slkj.shilixiaoyuanapp.entity.CommunityNewMessageEntity;
import com.slkj.shilixiaoyuanapp.entity.CommuntiyDetailsEntity;
import com.slkj.shilixiaoyuanapp.net.HttpHeper;
import com.slkj.shilixiaoyuanapp.net.callback.CommonCallBack;
import com.slkj.shilixiaoyuanapp.view.DividerItemDecoration;
import com.slkj.shilixiaoyuanapp.view.MySwipeRefreshLayout;
import com.slkj.shilixiaoyuanapp.view.StateLayout;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

import static com.slkj.shilixiaoyuanapp.entity.code.UiCode.PAGE_COUNT;

@ActivityInfo(layout = R.layout.activity_new_message, title = "详情")
public class CommunityDetailsActivity extends BaseActivity {

    @InjectParam int id;
    @BindView(R.id.recycer)
    RecyclerView recycer;
    BaseQuickAdapter adapter;
    @BindView(R.id.layout_root)
    StateLayout stateLayout;
    @BindView(R.id.swipeLayout)
    MySwipeRefreshLayout refreshLayout;
    List<CommunityEntity> datas = new ArrayList<>();

    @Override
    protected void init() {
        CommunityDetailsActivity__JumpCenter.bind(this);
        refreshLayout.setEnabled(false);
        recycer.setLayoutManager(new LinearLayoutManager(this));
        recycer.addItemDecoration(new DividerItemDecoration(this, LinearLayoutManager.VERTICAL));
        HttpHeper.get().comunityService()
                .getCommunityDetails(id)
                .compose(bindToLifecycle())
                .compose(getThread())
                .subscribe(new CommonCallBack<CommuntiyDetailsEntity>(stateLayout) {
                    @Override
                    public void onCallBackSuccess(CommuntiyDetailsEntity data) {
                        datas.add(data.getClassDynamic());
                        adapter = new CommunityAdapter(datas, CommunityDetailsActivity.this);
                        recycer.setAdapter(adapter);
                    }

                });
    }
}
